package com.game.chinesechess.piece.specific;


import com.game.chinesechess.piece.chess;
import com.game.chinesechess.util.Point;

public class horseChess extends chess {
    public horseChess(Color color, int x, int y) {
        this.color = color;
        this.point = new Point(x, y);
    }

    @Override
    public Boolean check(chess[][] map, int toX, int toY) {
        int xDistance = Math.abs(this.point.x - toX);
        int yDistance = Math.abs(this.point.y - toY);
        if (!((xDistance == 1 && yDistance == 2) || (xDistance == 2 && yDistance == 1)))
            return false;
        int block_X = (this.point.x + toX) / 2;
        int block_y = (this.point.y + toY) / 2;
        if (yDistance == 2)
            return map[this.point.x][block_y] == null;
        else
            return map[block_X][this.point.y] == null;
    }

    @Override
    public String getName() {
        return "马";
    }
}
